// src\ToolTabCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "ToolTabCtrl.h"
#include <afx.h>


// CToolTabCtrl

IMPLEMENT_DYNAMIC(CToolTabCtrl, CTabCtrl)

CToolTabCtrl::~CToolTabCtrl()
{
}


BEGIN_MESSAGE_MAP(CToolTabCtrl, CTabCtrl)
//	ON_NOTIFY_REFLECT(TCN_SELCHANGE, &CToolTabCtrl::OnTcnSelchange)
	ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
	ON_MESSAGE(DM_GETDEFID, OnGetDefID)
END_MESSAGE_MAP()

//Constructor for the class derived from CTabCtrl
CToolTabCtrl::CToolTabCtrl()
{
	m_DialogID[0] = IDD_ROBOT_DLG;
	m_DialogID[1] = IDD_PARTS_DLG;


	m_Dialog[0] = new CRobotDlg();
	m_Dialog[1] = new CPartsDlg();

	m_nPageCount = NUM_TOOL_TABS;

}

//This function creates the Dialog boxes once
void CToolTabCtrl::InitDialogs()
{
	m_Dialog[0]->Create(m_DialogID[0],GetParent());
	m_Dialog[1]->Create(m_DialogID[1],GetParent());
}

//Selection change event for the class derived from CTabCtrl
void CToolTabCtrl::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	ActivateTabDialogs();
	*pResult = 0;
}

void CToolTabCtrl::ActivateTabDialogs()
{
	int nSel = GetCurSel();
	if(m_Dialog[nSel]->m_hWnd)
		m_Dialog[nSel]->ShowWindow(SW_HIDE);

	CRect l_rectClient;
	CRect l_rectWnd;

	GetClientRect(l_rectClient);
	AdjustRect(FALSE,l_rectClient);
	GetWindowRect(l_rectWnd);
	GetParent()->ScreenToClient(l_rectWnd);
	l_rectClient.OffsetRect(l_rectWnd.left,l_rectWnd.top);
	for(int nCount=0; nCount < m_nPageCount; nCount++){
		m_Dialog[nCount]->SetWindowPos(&wndTop, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_HIDEWINDOW);
	}
	m_Dialog[nSel]->SetWindowPos(&wndTop, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_SHOWWINDOW);

	m_Dialog[nSel]->ShowWindow(SW_SHOW);

}

LRESULT CToolTabCtrl::OnGetDefID(WPARAM wp, LPARAM lp) 
{
    return MAKELONG(0,DC_HASDEFID); 
}



// CToolTabCtrl message handlers


